<?php echo $header;?>
<div class="box">
    <div class="content">
        <h2 class="h2title">Received File</h2>
        <div>
            <div class="warning" style="margin-top:10px;display:none;">
            </div>
            <table style="width:100%;padding:20px;">
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">File No</span>
                    </td>
                    <td>
                        <input type="text" id="txtfileno" name="txtfileno" class="txt" maxlength="50"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Receiving Date</span>
                    </td>
                    <td>
                        <input type="text" id="txtreceivingdate" name="txtreceivingdate" class="txt" disabled="true" value="<?php echo date('m/d/y'); ?>"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Receiving Time</span>
                    </td>
                    <td>
                        <input type="text" id="txtreceivingtime" name="txtreceivingtime" class="txt" disabled="true" value="<?php echo $stime; ?>"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Received By</span>
                    </td>
                    <td>
                        <input type="text" id="txtreceivedby" name="txtreceivedby" class="txt" maxlength="50" disabled="true" value="<?php echo $this->user->getFirstName(); ?>"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Department</span>
                    </td>
                    <td>
                        <select id="seldeptid" disabled="true" class="sel" style="width: 205px;">
                            <option value="">--select--</option>
                            <?php foreach($dept_list as $row){
							$selclass="";
							if($row["department_id"]==$this->user->getDepartmentId()){
							$selclass="selected";
							} 
							?>
                            <option value="<?php echo $row["department_id"]; ?>"
                                <?php echo $selclass;?>
                                >
                                <?php echo $row["name"]; ?>
                            </option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="buttonbar">
    <input type="button" value="Save" id="btnsave" name="btnsave" class="btnradius" style="margin-right:10px;"/><input type="button" value="Reset" id="btnreset" name="btnreset" class="btnradius"/>
</div>
<script type="text/javascript">
    /*
     $("#txtreceivingdate").datepicker({
     changeMonth: true,
     changeYear: true
     });
     $('#txtreceivingtime').timepicker({
     'timeFormat': 'H:i:s',
     'step': 5
     });
     */
    $("#btnsave").click(function(){
        if (validate()) {
            loading("show");
            $.ajax({
                url: "<?php echo MAIN_PAGE.'receivedfile/receivedfilepost';?>",
                type: 'POST',
                data: {
                    fileno: $("#txtfileno").val(),
                    receivedate: $("#txtreceivingdate").val(),
                    receivetime: $("#txtreceivingtime").val(),
                    receivedby: $("#txtreceivedby").val(),
                    deptid: $("#seldeptid").val()
                },
                dataType: 'json',
                success: function(res){
                    loading('hide');
                    if (res.status) {
                        alert(res.msg);
                        $("#btnreset").trigger("click");
                    }
                    else {
                        alert(res.msg);
                    }
                }
            });
        }
    });
    
    $("#btnreset").click(function(){
        $(".warning").hide();
        var txtarr = ["txtfileno"];
        for (var i = 0; i < txtarr.length; i++) {
            $("#" + txtarr[i]).val("");
        }
        //$("#seldeptid option:first").attr('selected', 'selected');
        var now = new Date();
        $("#txtreceivingdate").val(now.format("mm/dd/yy"));
        $("#txtreceivingtime").val(now.format("isoTime"));
    });
    
    function validate(){
        $(".warning").hide();
        if ($("#txtfileno").val() == "") {
            $("#txtfileno").focus();
            $(".warning").text("Please enter File No").show();
            return false;
        }
        if ($("#txtreceivingdate").val() == "") {
            $("#txtreceivingdate").focus();
            $(".warning").text("Please enter Receiving Date").show();
            return false;
        }
        if ($("#txtreceivingtime").val() == "") {
            $("#txtreceivingtime").focus();
            $(".warning").text("Please enter Receiving Time").show();
            return false;
        }
        if ($("#txtreceivedby").val() == "") {
            $("#txtreceivedby").focus();
            $(".warning").text("Please enter Receiving By").show();
            return false;
        }
        if ($("#seldeptid").val() == "") {
            $("#seldeptid").focus();
            $(".warning").text("Please choose department").show();
            return false;
        }
        return true;
    }
</script>
<?php echo $footer;?>
